package day02;

class Moon {
    private static Moon instance = null;

    private Moon() {
    }


    public synchronized static Moon getInstance() {
        if (instance == null) {
            instance = new Moon();
        }
        return instance;
    }
}

public class SingletonDemo {
    public static void main(String[] args) {

        Moon americaMoon = Moon.getInstance();
        Moon chineseMoon = Moon.getInstance();
        System.out.println(americaMoon);
        System.out.println(chineseMoon);
        System.out.println(americaMoon == chineseMoon);//必须是同一个对象返回True
        System.out.println(americaMoon.equals(chineseMoon));//内容相等，可以不是同一个对象 返回True


    }

}
